package com.liuwei.classy.controller;

import com.liuwei.classy.model.Pagination;
import com.liuwei.classy.model.Paper;
import com.liuwei.classy.model.Shiti;
import com.liuwei.classy.model.UserPaperStat;
import com.liuwei.classy.service.bizimpl.PaperServiceImpl;
import com.liuwei.classy.service.bizinter.IPaperService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.xml.ws.ResponseWrapper;
import java.util.List;

/**
 * Created by qingshengzheng on 17/11/18.
 */
@Controller
@EnableAutoConfiguration
@RequestMapping("/paper")
public class PaperController extends BaseController {
    @Autowired
    private IPaperService paperService;

    /**
     * 获取试卷详情
     *
     * @param pid
     * @return
     */
    @RequestMapping(value = "/paperdetail", method = RequestMethod.POST)
    @ResponseBody
    public String paperDetail(@RequestParam String pid) {
        Paper paper = paperService.getPaperByid(pid);
        return responseJson(paper);
    }

    /**
     * 获取试题详情
     *
     * @param aid
     * @return
     */
    @RequestMapping(value = "/answerdetail", method = RequestMethod.POST)
    @ResponseBody
    public String anserDetail(@RequestParam String aid) {
        Shiti shiti = paperService.getShitiByid(aid);
        return responseJson(shiti);
    }

    /**
     * 获取我的试卷统计信息
     *
     * @return
     */
    @RequestMapping(value = "/metotal", method = RequestMethod.POST)
    @ResponseBody
    public String meTotal() {
        Long uid = getHeader().getUid();
        UserPaperStat stat = paperService.getUserPaperStat(uid);
        return responseJson(stat);
    }

    /**
     * 包含aids列表的paper Detail
     * @param pid
     * @return
     */
    @RequestMapping(value = "/paperdetailIncludeAids", method = RequestMethod.GET)
    public String paperdetailIncludeAids(@RequestParam String pid) {
        Paper paper = paperService.getPaperByid(pid);
        return responseJson(paper);
    }


    /**
     * 获取试卷过滤信息
     *
     * @param paper
     * @param pageno
     * @param pagesize
     * @return
     */
    @PostMapping(value = "/paperfilter/{pageno}/{pagesize}")
    @ResponseBody
    public String paperFilter(@RequestBody(required = true) Paper paper, @PathVariable Integer pageno, @PathVariable Integer pagesize) {
        Long uid = getHeader().getUid();
        Pagination<Paper> page = new Pagination<Paper>(pageno, pagesize);
        List<Paper> vs = paperService.filterPaper(uid, paper, page);
        return responseJson(vs);
    }

    /**
     * 获取收藏的试卷列表
     *
     * @param pageno
     * @param pagesize
     * @return
     */
    @RequestMapping(value = "/collect/{pageno}/{pagesize}", method = RequestMethod.POST)
    @ResponseBody
    public String paperCollectList(@PathVariable Integer pageno, @PathVariable Integer pagesize) {
        Pagination<Paper> page = new Pagination<Paper>(pageno, pagesize);
        Long uid = getHeader().getUid();
        List<Paper> vs = paperService.getCollectPaper(uid, page);
        return responseJson(vs);
    }

    /**
     * 获取收藏的试题
     *
     * @param pageno
     * @param pagesize
     * @return
     */
    @RequestMapping(value = "/shiti/collect/{pageno}/{pagesize}", method = RequestMethod.POST)
    @ResponseBody
    public String shitiCollectList(@PathVariable Integer pageno, @PathVariable Integer pagesize) {
        Pagination<Shiti> page = new Pagination<Shiti>(pageno, pagesize);
        Long uid = getHeader().getUid();
        List<Shiti> vs = paperService.getCollectShiti(uid, page);
        return responseJson(vs);
    }


    /**
     * 获得看过的试卷
     *
     * @param pageno
     * @param pagesize
     * @return
     */
    @RequestMapping(value = "/view/history/{pageno}/{pagesize}", method = RequestMethod.POST)
    @ResponseBody
    public String shitiHistory(@PathVariable Integer pageno, @PathVariable Integer pagesize) {
        Pagination<Paper> page = new Pagination<Paper>(pageno, pagesize);
        Long uid = getHeader().getUid();
        List<Paper> vs = paperService.historyPaper(uid, page);
        return responseJson(vs);
    }

    /**
     * 收藏试卷
     *
     * @param pid
     * @return
     */
    @RequestMapping(value = "/collectPaper", method = RequestMethod.POST)
    @ResponseBody
    public String collectPaper(String pid) {
        Long uid = getHeader().getUid();
        paperService.collectPaper(uid, pid);
        return responseJson(null);
    }

    /**
     * 收藏试题
     */
    @RequestMapping(value = "/collectShiti", method = RequestMethod.POST)
    @ResponseBody
    public String collectShiti(String aid) {
        Long uid = getHeader().getUid();
        paperService.collectShiti(uid, aid);
        return responseJson(null);
    }

    /**
     * 获取试卷下的所有试题信息
     */

    public String shitisOfPaper(String pid) {

        return "";
    }


}
